package com.ruoyi.web.controller.system;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.system.domain.TablePProjectTask;
import com.ruoyi.system.service.ITablePProjectTaskService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TablePCapitalEquiment;
import com.ruoyi.system.service.ITablePCapitalEquimentService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备资金Controller
 * 
 * @author ruoyi
 * @date 2022-05-18
 */
@Controller
@RequestMapping("/system/equiment")
public class TablePCapitalEquimentController extends BaseController
{
    private String prefix = "system/equiment";

    @Autowired
    private ITablePCapitalEquimentService tablePCapitalEquimentService;

    @Autowired
    private ITablePProjectTaskService tablePProjectTaskService;

    @RequiresPermissions("system:equiment:view")
    @GetMapping()
    public String equiment()
    {
        return prefix + "/equiment";
    }

    /**
     * 查询设备资金列表
     */
    @RequiresPermissions("system:equiment:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TablePCapitalEquiment tablePCapitalEquiment)
    {
        startPage();
        List<TablePCapitalEquiment> list = tablePCapitalEquimentService.selectTablePCapitalEquimentList(tablePCapitalEquiment);
        return getDataTable(list);
    }

    /**
     * 导出设备资金列表
     */
    @RequiresPermissions("system:equiment:export")
    @Log(title = "设备资金", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TablePCapitalEquiment tablePCapitalEquiment)
    {
        List<TablePCapitalEquiment> list = tablePCapitalEquimentService.selectTablePCapitalEquimentList(tablePCapitalEquiment);
        ExcelUtil<TablePCapitalEquiment> util = new ExcelUtil<TablePCapitalEquiment>(TablePCapitalEquiment.class);
        return util.exportExcel(list, "设备资金数据");
    }

    /**
     * 新增设备资金
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {

        mmap.put("tablePTask", tablePProjectTaskService.selectTablePProjectTaskList(new TablePProjectTask()));
        return prefix + "/add";
    }

    /**
     * 新增保存设备资金
     */
    @RequiresPermissions("system:equiment:add")
    @Log(title = "设备资金", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TablePCapitalEquiment tablePCapitalEquiment)
    {
        return toAjax(tablePCapitalEquimentService.insertTablePCapitalEquiment(tablePCapitalEquiment));
    }

    /**
     * 修改设备资金
     */
    @RequiresPermissions("system:equiment:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TablePCapitalEquiment tablePCapitalEquiment = tablePCapitalEquimentService.selectTablePCapitalEquimentById(id);
        mmap.put("tablePCapitalEquiment", tablePCapitalEquiment);
        return prefix + "/edit";
    }

    /**
     * 审批设备资金
     */
    @RequiresPermissions("system:equiment:approve")
    @GetMapping("/approve/{id}")
    public String approve(@PathVariable("id") Long id, ModelMap mmap)
    {
        TablePCapitalEquiment tablePCapitalEquiment = tablePCapitalEquimentService.selectTablePCapitalEquimentById(id);
        mmap.put("tablePCapitalEquiment", tablePCapitalEquiment);
        mmap.put("tablePTask", tablePProjectTaskService.selectTablePProjectTaskList(new TablePProjectTask()));
        return prefix + "/approve";
    }


    /**
     * 审批设备资金
     */
    @RequiresPermissions("system:equiment:approve")
    @Log(title = "设备资金", businessType = BusinessType.UPDATE)
    @PostMapping("/approve")
    @ResponseBody
    public AjaxResult approve(TablePCapitalEquiment tablePCapitalEquiment)
    {
        tablePCapitalEquiment.setApproveId((ShiroUtils.getSysUser().getUserId()));
        tablePCapitalEquiment.setApproveTime(new Date());
        return toAjax(tablePCapitalEquimentService.updateTablePCapitalEquiment(tablePCapitalEquiment));
    }

    /**
     * 修改保存设备资金
     */
    @RequiresPermissions("system:equiment:edit")
    @Log(title = "设备资金", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TablePCapitalEquiment tablePCapitalEquiment)
    {
        return toAjax(tablePCapitalEquimentService.updateTablePCapitalEquiment(tablePCapitalEquiment));
    }

    /**
     * 删除设备资金
     */
    @RequiresPermissions("system:equiment:remove")
    @Log(title = "设备资金", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tablePCapitalEquimentService.deleteTablePCapitalEquimentByIds(ids));
    }
}
